package com.qinghong.blog.service.impl;

import com.qinghong.blog.entity.Menu;
import com.qinghong.blog.entity.UserAuth;
import com.qinghong.blog.entity.UserInfo;
import com.qinghong.blog.mapper.MenuMapper;
import com.qinghong.blog.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qinghong.blog.vo.ConditionVO;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qinghong
 * @since 2021-12-06
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Override
    public List<Menu> getMenusWithRole() {
        return baseMapper.getMenusWithRole();
    }

    @Override
    public List<Menu> listMenus(ConditionVO conditionVO) {
        String keywords = conditionVO.getKeywords();
        return baseMapper.listMenus(keywords);
    }

    @Override
    public List<Menu> listUserMenus() {
        Integer userId = ((UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId();
        return baseMapper.listMenusByUserId(userId);
    }
}
